<%@ page isELIgnored="false" language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core_rt" %>
<c:set var="_path" value="${pageContext.request.contextPath}"></c:set>
<form id="queryForm" style="margin:10;text-align: center;">
	<table width="100%">
		<tr>
			<td>身份证：</td>
			<td>
				<input name="q@idnumber" style="width: 200"/>
			</td>
			<td>一卡通号：</td>
			<td>
				<input name="q@abaid" style="width: 200"/>
			</td>
			<td>商户名称(简)：</td>
			<td>
				<input name="q@namesimp" style="width: 200"/>
			</td>
			<td align="center">
				<a href="javascript:void(0);" onclick="clearForm()" class="easyui-linkbutton" iconCls="icon-search">清空</a>
			</td>
		</tr>
		<tr>
			<td>消费流水号：</td>
			<td>
				<input name="q@serialnumber" style="width: 200"/>
			</td>
			<td>消费时间从：</td>
			<td>
				<input class="easyui-datebox" name="q@dateFrom" style="width: 200"/>
			</td>
			<td>消费时间到：</td>
			<td>
				<input class="easyui-datebox" name="q@dateTo" style="width: 200"/>
			</td>
			<td align="center"><a href="javascript:void(0);" onClick="doSearch()" class="easyui-linkbutton" iconCls="icon-search">查询</a></td>
		</tr>
	</table>
</form>
<div id="acaTable"></div>
<script>
var moneyType = ${json.aba};
jQuery(function($){
	$('#acaTable').datagrid({
		title:'公共账户消费列表',//标题
		method:'post',
		iconCls:'icon-edit',//图标
		singleSelect:false,//多选
		height:380, //高度
		fitColumns: true,//自动调整各列，用了这个属性，下面各列的宽度值就只是一个比例。
		striped: true,//奇偶行颜色不同
		collapsible:false,//可折叠
		url:"aca/queryList?q@orderflg=1", //数据来源
		sortName: 'id', //排序的列
		sortOrder: 'desc', //倒序
		remoteSort: true, //服务器端排序
		idField:'id', //主键字段
		queryParams:{}, //查询条件
		pagination:true, //显示分页
		rownumbers:true, //显示行号
		columns:[[
			{field:'ck',checkbox:true,width:2}, //显示复选框
			{field:'aaa.username',title:'姓名',width:20,sortable:true,formatter:function(v,r){return r.aba.aaa.username;}},
			{field:'aaa.ownercard',title:'身份证',width:20,sortable:true,formatter:function(v,r){return r.aba.aaa.ownercard;}},
			{field:'abaid',title:'卡号',width:20,sortable:true},
			{field:'serialnumber',title:'消费流水',width:20,sortable:true},
			{field:'consmoney',title:'消费金额',width:20,sortable:true},
			{field:'fee',title:'手续费',width:20,sortable:true},
			{field:'beginconsmoney',title:'消费前余额',width:20,sortable:true},
			{field:'endconsmoney',title:'消费后余额',width:20,sortable:true},
			{field:'aac.cardkey',title:'POS机编号',width:20,sortable:true,formatter:function(v,r){return r.aac.cardkey;}},
			{field:'aab.namesimp',title:'商户名称(简)',width:20,sortable:true,formatter:function(v,r){return r.aab.namesimp;}},
			{field:'moneytype',title:'帐户种类',width:20,sortable:true,formatter:function(v,r){return moneyType[v]}},
			{field:'consdate',title:'消费时间',width:20,sortable:true}
		]],
		toolbar:[{
			text:'退货',
			iconCls:'icon-add',
			handler:function(){
				updaterow();
			}
		},'-'],
		onLoadSuccess:function(){
			$('#acaTable').datagrid('clearSelections'); //一定要加上这一句，要不然datagrid会记住之前的选择状态，删除时会出问题
		}
	});
});
function updaterow(){
	var rows = $('#acaTable').datagrid('getSelections');
	//这里有一个jquery easyui datagrid的一个小bug，必须把主键单独列出来，要不然不能多选
	if(rows.length==0){
		$.messager.alert('提示',"请选择退货的消费记录!",'info');
		return;
	}
	if(rows.length > 1){
		$.messager.alert('提示',"只能选择一个消费记录退货",'info');
		return;
	}
	showWindow({
			title:'消费退货',
			href:'${_path}/aca/acaReturnPopWindow?acaid='+ rows[0].id,
			width:500,
			height:450
		});
}
//表格查询
function doSearch(){
	var params = $('#acaTable').datagrid('options').queryParams;//先取得 datagrid的查询参数
	var fields =$('#queryForm').serializeArray();//自动序列化表单元素为JSON对象
	$.each( fields, function(i, field){
		params[field.name] = field.value;//设置查询参数
	}); 
	$('#acaTable').datagrid('reload');
}
//清空查询条件
function clearForm(){
	$('#queryForm').form('clear');
	doSearch();
}
</script>